package com.lvw.weather.gateway.filter

import com.netflix.zuul.ZuulFilter
import com.netflix.zuul.context.RequestContext
import com.netflix.zuul.exception.ZuulException
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import javax.servlet.http.HttpServletRequest

class LogFilter extends ZuulFilter {

    private static final Logger log = LoggerFactory.getLogger(LogFilter.class);

    @Override
    String filterType() {
        return "pre";
    }

    @Override
    int filterOrder() {
        return 0;
    }

    @Override
    boolean shouldFilter() {
        return true;
    }

    @Override
    Object run() throws ZuulException {

        RequestContext context = RequestContext.getCurrentContext();

        HttpServletRequest request = context.getRequest();

        log.info("=== {} {}", request.getMethod(), request.getRequestURI());

        return null;
    }
}
